package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @param
 * @return
 */
@Mapper
public interface OrderMapper {

    void Insert(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber} and user_id=#{id}")
    Orders getByNumber(String orderNumber,Long id);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    @Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus} ,checkout_time = #{check_out_time} where id = #{id}")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime check_out_time, Long id);
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * id查询订单
     * @param id
     * @return
     */
    @Select("select *from orders where id=#{id}")
    Orders getById(Long id);

    /**
     * 根据状态统计订单数量
     * @param status
     * @param userId
     * @return
     */
    @Select("select count(id)from orders where status=#{status} and user_id=#{userId}")
    Integer countStatus(Integer status,Long userId);

    /**
     * 根据订单状态和下单时间查询订单
     * @param status
     * @param ordertime
     * @return
     */
    @Select("select *from orders where status=#{status} and order_time<#{ordertime}")
    List<Orders>getByStatusAndOrderTimeLT(Integer status,LocalDateTime ordertime);

    /**
     *统计当天营业数据
     * @param map
     * @return
     */
    Double sumByMap(Map map);

    /**
     * 根据动态条件统计订单数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

    /**
     * 统计指定时间区间内的销量排名前十
     * @param begin
     * @param end
     * @return
     */
    List<GoodsSalesDTO>getSalesTop10(LocalDateTime begin,LocalDateTime end);
}
